package com.itheima.exception;

import com.itheima.common.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import java.sql.SQLIntegrityConstraintViolationException;
//全局异常处理类
@ControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(SQLIntegrityConstraintViolationException.class )
    @ResponseBody
    public R ex1(SQLIntegrityConstraintViolationException ex){
        return R.error("用户已存在");
    }

    @ExceptionHandler(CustomException.class )
    @ResponseBody
    public R ex1(CustomException ex){
        return R.error(ex.getMessage());
    }
}
